<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Route_Expense_List2 extends Page
{
       public $lbldispatch = null;
       public $Label3 = null;
       public $lblmodel = null;
       public $lblmake = null;
       public $Label2 = null;
       public $Label1 = null;
       public $lblyear = null;
       public $lblplate = null;
       public $lblEmpName = null;
       public $lblEmpId = null;
       public $JTJavaScript1 = null;
       public $hiddenRoute = null;
       public $hiddenEmp = null;
       public $JTExpenseList = null;
       public $imgAdd = null;
       public $JTSiteTheme1 = null;
       public $imgBack = null;
       public $Image3 = null;

       function imgAddJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new.png"
       <?php

       }

       function imgAddJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new_blue.png"
       <?php

       }


       function commafy($_)
       {
        return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,' , strrev( $_ ) ) );
       }



       function Route_Expense_List2Create($sender, $params)
       {
       if($_SESSION['isAdmin']!=1)
       {
       $this->imgAdd->setVisible(false);
       }


        $emp_id = $_GET['emp'];
        $this->hiddenEmp->setValue($emp_id);
        $route_id = $_GET['route'];
        $this->hiddenRoute->setValue($route_id);


       if($_SESSION['access_route']==1)
       {
       $this->imgAdd->Visible=false;
       }

       if($_SESSION['access_route']==2)
       {
       $this->imgAdd->Visible=true;
       }

       $this->imgBack->setLink('route_list2.php?emp='.$this->hiddenEmp->getValue().'&route='.$this->hiddenRoute->getValue());
       $this->imgAdd->setLink('route_expense_create2.php?emp='.$this->hiddenEmp->getValue().'&route='.$this->hiddenRoute->getValue());

       $query_emp = "select * from vehicle_tbl where vehicle_id='".$this->hiddenEmp->getValue()."'";
       $result_emp = mysql_query($query_emp)or die(mysql_error());
       $row_emp = mysql_fetch_array($result_emp);

       $this->lblplate->Caption=$row_emp['veh_num'];
       $this->lblyear->Caption=$row_emp['year'];
       $this->lblmake->Caption=$row_emp['manufacturer_name'];
       $this->lblmodel->Caption=$row_emp['model_name'];


       $query_veh = "select * from route_tbl where route_id='".$this->hiddenRoute->getValue()."'";
       $result_veh = mysql_query($query_veh)or die(mysql_error());
       $row_veh = mysql_fetch_array($result_veh);

       $this->lbldispatch->Caption=$row_veh['job_no'];



       }

       function JTExpenseListShow($sender, $params)
       {
       $query = "SELECT * FROM rou_expense_tbl WHERE route_id='".$this->hiddenRoute->getValue()."'";
       $result = mysql_query($query)or die(mysql_error());

        $arr = array();
        while($row = mysql_fetch_array($result))
          {

          $emp = $this->hiddenEmp->getValue();
          $route = $this->hiddenRoute->getValue();

          $exp_t = $row['type'];
          $result_exp = mysql_query("select * from lookup_expense_tbl where company_id = '".$_SESSION['company_id']."' AND id='".$exp_t."'");
          $row_exp = mysql_fetch_array($result_exp);
          $exp = $row_exp['value'];

          $tools="<img onclick=js_deleteExpense('".$emp."','".$route."','".$row['expense_id']."'); src='image/delete.png' title='delete' style='cursor:pointer'>";
          //"<a href=route_expense_delete.php?emp=".$emp."&route=".$route."&expense=".$row['expense_id']."><img src='image/delete_orange.jpg' title='delete' no border></a>";
          $type = "<a href=route_expense_edit2.php?emp=".$emp."&route=".$route."&expense=".$row['expense_id']." title='edit route expense'>".$exp."</a>";
          $amt = $row['amount'];
          $camt = $this->commafy($amt);

            if($_SESSION['access_route']==2)
            {
             $arr[] = array(
                        'Account Type' => $type,
                        'Amount' => "<div style='text-align:right'>".$camt."</div>",
                        //'Description' => $row['type'],
                        'Tools' => $tools
                        );

            }

            if($_SESSION['access_route']==1)
            {
             $arr[] = array(
                        'Account Type' => $type,
                        'Amount' => "<div style='text-align:right'>".$camt."</div>"
                        //'Description' => $row['type']
                        );

            }


          }

            $this->JTExpenseList->setCellData($arr);

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
        document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
        document.images['imgBack'].src="image/btn_back.png"
       <?php

       }


}

global $application;

global $Route_Expense_List2;

//Creates the form
$Route_Expense_List2=new Route_Expense_List2($application);

//Read from resource file
$Route_Expense_List2->loadResource(__FILE__);

//Shows the form
$Route_Expense_List2->show();

?>